import paramiko

def upload_file(local_path, remote_path, host, port, username, password):
    # 创建 SSH 客户端对象
    ssh = paramiko.SSHClient()

    # 允许连接不在 known_hosts 文件中的主机
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    # 连接到远程服务器
    ssh.connect(host, port=port, username=username, password=password)

    # 使用 SCP 传输文件
    sftp = ssh.open_sftp()
    sftp.put(local_path, remote_path)
    sftp.close()

    # 关闭 SSH 连接
    ssh.close()

# 示例使用
local_path = r'D:\Desktop\pythonProject\小玩意\樱花树.py'
remote_path = r'C:\Users\Administrator\Desktop'
host = '192.168.8.128'
port = 22
username = 'Administrator'
password = ''

upload_file(local_path, remote_path, host, port, username, password)
